package net.sxnic.ugr.role.action;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import net.sxinfo.core.dao.Page;
import net.sxnic.ugr.UgrActionSupport;
import net.sxnic.ugr.menu.Menu;
import net.sxnic.ugr.menu.MenuManager;
import net.sxnic.ugr.permission.Permission;
import net.sxnic.ugr.permission.PermissionManager;
import net.sxnic.ugr.resource.Resource;
import net.sxnic.ugr.resource.ResourceManager;
import net.sxnic.ugr.role.Role;
import net.sxnic.ugr.role.RoleManager;

import org.springframework.beans.factory.annotation.Autowired;

@SuppressWarnings("serial")
public abstract class RoleAction extends UgrActionSupport {

	protected Role role;

	protected Page roles;
	
	protected String menu;
	
	protected String[] perms;
	
	protected String[] menus;	
	
	protected String menuHtml;

	protected Map<Resource,List<Permission>> permMapList;

	@Autowired
   	protected RoleManager roleManager;
    
    @Autowired
   	protected MenuManager menuManager;
    
    @Autowired
   	protected ResourceManager resourceManager;
    
    @Autowired
   	protected PermissionManager permissionManager;
	
    protected void loadPermMapList(){
    	
    	permMapList = new LinkedHashMap<Resource,List<Permission>>();
		
		List<Resource> resList = resourceManager.getAll();
		
		List<Permission> permList;
		
		for(Resource res : resList){
			//根据资源Id获取权限列表
			permList = permissionManager.getListByResId(res.getId());
			if(permList!=null && permList.size()>0){
				//如果资源下的权限不为空，则列入Map，作为前台显示使用。
				permMapList.put(res, permList);
				
			}
		}
		
	}    
    
//    protected void loadMenuTree(){
//    	
//		menu = new Menu();
//		menu.setValue("全部菜单");
//		menu.setId("*");
//		//dept.setTreeLeaf(false);
//		Set<Menu> cateSet = new LinkedHashSet<Menu>();
//		List<Menu> cates = menuManager.getTopList();
//		if(cates!=null && cates.size()>0) {
//			for(Menu cate:cates) {
//				if(cate!=null)
//					cateSet.add(cate);
//			}
//		}
//		menu.setChild(cateSet);
//    	
//    	
//    }
    

	public Map<Resource,List<Permission>> getPermMapList() {
		return permMapList;
	}

	public void setPermMapList(Map<Resource,List<Permission>> permMapList) {
		this.permMapList = permMapList;
	}
    
    public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public Page getRoles() {
		return roles;
	}

	public void setRoles(Page roles) {
		this.roles = roles;
	}
	
	public String getMenu() {
		return menu;
	}

	public void setMenu(String menu) {
		this.menu = menu;
	}

	public String[] getMenus() {
		return menus;
	}

	public void setMenus(String[] menus) {
		this.menus = menus;
	}

	public String[] getPerms() {
		return perms;
	}

	public void setPerms(String[] perms) {
		this.perms = perms;
	}

	public String getMenuHtml() {
		return menuHtml;
	}

	public void setMenuHtml(String menuHtml) {
		this.menuHtml = menuHtml;
	}


}
